//; ---------------------------------------------------------------------------
//; Object 28 - animals
//; ---------------------------------------------------------------------------
#include "animals.h"

#include "points.h"
#include "../sprite.h"
#include "../objectsystemNEWER.h"
#include "../misc.h"

static object *obj;

#define player objects[0]
extern object *objects;

extern byte v_zone;
extern byte v_bossstatus;

//; ---------------------------------------------------------------------------
//; Sprite mappings - animals
//; ---------------------------------------------------------------------------
byte byte_946C[6] = { 1,
		   0xF4, 6, 0,	0, 0xF8
};
byte byte_9472[6] = { 1,
	           0xF4, 6, 0,	6, 0xF8
};
byte byte_9478[6] = { 1,
		   0xF4, 6, 0, 0xC,0xF8
};
byte byte_9484[6] = { 1,
		   0xF4, 6, 0,	0, 0xF8
};
byte byte_948A[6] = { 1,
		   0xFC, 5, 0,	6, 0xF8
};
byte byte_9490[6] = { 1,
		   0xFC, 5, 0,0xA, 0xF8
};
byte byte_949C[6] = { 1,
		   0xF4, 6, 0,	0, 0xF8
};
byte byte_94A2[6] = { 1,
		   0xFC, 9, 0,	6, 0xF4
};
byte byte_94A8[6] = { 1,
		   0xFC, 9, 0,0xC, 0xF4
};

byte *Map_Animal1[3] = { byte_9472, byte_9478, byte_946C };
byte *Map_Animal2[3] = { byte_948A, byte_9490, byte_9484 };
byte *Map_Animal3[3] = { byte_94A2, byte_94A8, byte_949C };

void (*Anml_Index[21])() = { Anml_Ending, loc_912A,
                                loc_9184, loc_91C0, loc_9184, loc_9184, loc_9184, loc_91C0, loc_9184, 
  loc_9240, loc_9260, loc_9260, loc_9280, loc_92BA, loc_9314, loc_9332, loc_9314, loc_9332, loc_9314, loc_9370, loc_92D6 
};


//Animals:				; XREF: Obj_Index
void Animals(object *_obj)
{
    obj = _obj;

    //moveq	#0,d0
    //move.b	obRoutine(a0),d0
    byte routine = obj->Routine/2;
    
    //move.w	Anml_Index(pc,d0.w),d1
    //jmp	Anml_Index(pc,d1.w)
    (*Anml_Index[routine])();

}   //; ===========================================================================


byte Anml_VarIndex[12] = { 0, 5,       //GHZ         //depending on zone, first or second is selected at random as index to grab into Anml_Variables..
                           2, 3,       //LZ          //this value is also placed in 0x30, used as animal type
                           6, 3,       //MZ
                           4, 5,       //SLZ
                           4, 1,       //SYZ
                           0, 1        //SBZ
};
 
struct anVar
{
    word hspeed, vspeed;
    byte** Map;
} Anml_Variables[7] = { 
{ 0xFE00, 0xFC00, Map_Animal1 },
{ 0xFE00, 0xFD00, Map_Animal2 },
{ 0xFE80, 0xFD00, Map_Animal1 },
{ 0xFEC0, 0xFE80, Map_Animal2 },
{ 0xFE40, 0xFD00, Map_Animal3 }, 
{ 0xFD00, 0xFC00, Map_Animal2 },
{ 0xFD80, 0xFC80, Map_Animal3 }
};

//Anml_EndSpeed:	dc.w $FBC0, $FC00, $FBC0, $FC00, $FBC0,	$FC00, $FD00, $FC00
//			dc.w $FD00, $FC00, $FE80, $FD00, $FE80,	$FD00, $FEC0, $FE80
//			dc.w $FE40, $FD00, $FE00, $FD00, $FD80,	$FC80
word Anml_EndSpeed[22] = { 0xFBC0, 0xFC00, 0xFBC0, 0xFC00, 0xFBC0, 0xFC00, 0xFD00, 0xFC00,
                           0xFD00, 0xFC00, 0xFE80, 0xFD00, 0xFE80, 0xFD00, 0xFEC0, 0xFE80,
                           0xFE40, 0xFD00, 0xFE00, 0xFD00, 0xFD80, 0xFC80 
};

byte **Anml_EndMap[11] = { Map_Animal2, Map_Animal2, Map_Animal2, Map_Animal1, Map_Animal1,
		           Map_Animal1, Map_Animal1, Map_Animal2, Map_Animal3, Map_Animal2,
		           Map_Animal3
};

word Anml_EndVram[11] 	= { 0x5A5, 0x5A5, 0x5A5, 0x553, 0x553, 0x573, 0x573, 0x585, 0x593,
		            0x565, 0x5B3
};

//; ===========================================================================

//Anml_Ending:	; Routine 0
void Anml_Ending()
{
    //tst.b	obSubtype(a0)	; did animal come from a destroyed enemy?
    //beq.w	Anml_FromEnemy	; if yes, branch
    if (obj->Subtype != 0)
    {	
	//moveq	#0,d0
	//move.b	obSubtype(a0),d0 ; move object type to d0
        //add.w	        d0,d0		; multiply d0 by 2
        word anmlType = obj->Subtype * 2;

	//move.b	d0,obRoutine(a0) ; move d0 to routine counter
        obj->Routine = anmlType;

	//subi.w	#$14,d0
        word anmlGfxIndex = anmlType - 0x14;

	//move.w	Anml_EndVram(pc,d0.w),obGfx(a0)
        obj->Gfx = Anml_EndVram[anmlGfxIndex];

	//add.w	d0,d0
        word anmlMapIndex = anmlGfxIndex * 2;

	//move.l	Anml_EndMap(pc,d0.w),obMap(a0)
        obj->Map = Anml_EndMap[anmlMapIndex];

	//lea	Anml_EndSpeed(pc),a1
	//move.w	(a1,d0.w),$32(a0) ; load horizontal speed
        ptrsetobjvariableword(0x32, obj, Anml_EndSpeed[anmlMapIndex])	
 	
        //move.w	(a1,d0.w),obVelX(a0)
        obj->VelocityX = Anml_EndSpeed[anmlMapIndex];
        
	//move.w	2(a1,d0.w),$34(a0) ; load vertical speed
       	ptrsetobjvariableword(0x32, obj, Anml_EndSpeed[anmlMapIndex+1])

	//move.w	2(a1,d0.w),obVelY(a0)
        obj->VelocityY = Anml_EndSpeed[anmlMapIndex+1];

	//move.b	#$C,obHeight(a0)
        obj->Height = 12;

	//move.b	#4,obRender(a0)
        obj->Render = 4;

	//bset	#0,obRender(a0)
        obj->Render = obj->Render | 1;

	//move.b	#6,obPriority(a0)
        obj->Priority = 6;

	//move.b	#8,obActWid(a0)
        obj->ActionWidth = 8;
	
	//move.b	#7,obTimeFrame(a0)
        obj->TimeFrame = 7;
	
	//bra.w	DisplaySprite
        DisplaySprite(obj);

    }//; ===========================================================================

    else
    {
        //Anml_FromEnemy:			; XREF: Anml_Ending
	//addq.b	#2,obRoutine(a0)
        obj->Routine = obj->Routine + 2;

	//bsr.w	RandomNumber
        word random = RandomNumber();

	//andi.w	#1,d0
        word scaledRandom = random & 1;

	//moveq	#0,d1
	//move.b	(v_zone).w,d1
	//add.w	d1,d1
        word zoneOffset = v_zone * 2;

	//add.w	d0,d1
        word varIndexOffset = zoneOffset + scaledRandom;

	//lea	Anml_VarIndex(pc),a1
	//move.b	(a1,d1.w),d0
        byte anmlVar = Anml_VarIndex[varIndexOffset];

	//move.b	d0,$30(a0)
        obj->Variables[0x30-0x28] = anmlVar;

	//lsl.w	#3,d0                   
        //word varIndex = anmlVar*8;    aka sizeof(anVar)
        word varIndex = anmlVar;
 
	//lea	Anml_Variables(pc),a1
        //adda.w	d0,a1
        anVar curVars = Anml_Variables[varIndex];

	//move.w	(a1)+,$32(a0)	; load horizontal speed
        ptrsetobjvariableword(0x32, obj, curVars.hspeed);

	//move.w	(a1)+,$34(a0)	; load vertical	speed
        ptrsetobjvariableword(0x34, obj, curVars.vspeed);

	//move.l	(a1)+,obMap(a0)	; load mappings
        obj->Map = curVars.Map;

	//move.w	#$580,obGfx(a0)	; VRAM setting for 1st animal
        obj->Gfx = 0x580;
	
	//btst	#0,$30(a0)	; is 1st animal	used?
        //beq.s	loc_90C0	; if yes, branch
        if ((obj->Variables[0x30-0x28] & 1) != 0)
        {
            //move.w	#$592,obGfx(a0)	; VRAM setting for 2nd animal
            obj->Gfx = 0x592;
        }
  
        //loc_90C0:
	//move.b	#$C,obHeight(a0)
        obj->Height = 12;

	//move.b	#4,obRender(a0)
        obj->Render = 4;

	//bset	#0,obRender(a0)
        obj->Render = obj->Render | 1;

	//move.b	#6,obPriority(a0)
        obj->Priority = 6;

	//move.b	#8,obActWid(a0)
        obj->ActionWidth = 8;

	//move.b	#7,obTimeFrame(a0)
        obj->TimeFrame = 7;
	
	//move.b	#2,obFrame(a0)
        obj->Frame = 2;

	//move.w	#-$400,obVelY(a0)
        obj->VelocityY = -0x400;

	//tst.b	(v_bossstatus).w
        //bne.s	loc_911C
        if (v_bossstatus == 0)
        {
	    //bsr.w	FindFreeObj
            object *points = FindFreeObj();

	    //bne.s	Anml_Display
            if (points->ID == 0)
            {
                //move.b	#id_Points,0(a1) ; load points object
	        points->ID = id_Points;

                //move.w	obX(a0),obX(a1)
		points->X = obj->X;

                //move.w	obY(a0),obY(a1)
		points->Y = obj->Y;

                //move.w	$3E(a0),d0
		//lsr.w	#1,d0
                word pointsType = ptrgetobjvariableword(0x3E, obj)/2;

		//move.b	d0,obFrame(a1)
                points->Frame = pointsType;

            }
            
            //Anml_Display:
	    //bra.w	DisplaySprite
            DisplaySprite(obj);
        }
        //; ===========================================================================
        else
        {
            //loc_911C:
	    //move.b	#$12,obRoutine(a0)
            obj->Routine = 0x12;

	    //clr.w	obVelX(a0)
            obj->VelocityX = 0;

	    //bra.w	DisplaySprite
            DisplaySprite(obj);
    
        }   //; ===========================================================================
    }
}

//loc_912A:				; XREF: Anml_Index
void loc_912A()                         //INITIAL BEHAVIOR FOR ALL ANIMALS
{
    //tst.b	obRender(a0)
    //bpl.w	DeleteObject
    if (obj->Render < 0x80)
    {
        DeleteObject(obj);
    }
    else                                //ANIMAL FALLS FROM HEIGHT (UNLESS ALREADY GROUNDED) OF DESTROYED ENEMY UNTIL GROUND IS REACHED 
    {                                   //WHEN REACHING GROUND, A ROUTINE INDEPENDENT OF ANIMAL TYPE (0x30) IS SELECTED 
        //bsr.w	ObjectFall
        ObjectFall(obj);

	//tst.w	obVelY(a0)
        //bmi.s	loc_9180
        if (obj->VelocityY >= 0) 
        {
	    //jsr	ObjFloorDist
            signed short floorDist = ObjFloorDist(obj);

	    //tst.w	d1
            //bpl.s	loc_9180
            if (floorDist < 0)
            {
                //add.w	d1,obY(a0)
                obj->Y = obj->Y + floorDist;

		//move.w	$32(a0),obVelX(a0)
                obj->VelocityX = ptrgetobjvariableword(0x32, obj);

		//move.w	$34(a0),obVelY(a0)
                obj->VelocityY = ptrgetobjvariableword(0x34, obj);

		//move.b	#1,obFrame(a0)
                obj->Frame = 1;

		//move.b	$30(a0),d0
                //add.b	d0,d0
		//addq.b	#4,d0
                byte routine = (obj->Variables[0x30-0x28]*2) + 4;  //+4 skips first 2 initial routines selecting the correct routine for this animal type

		//move.b	d0,obRoutine(a0)
                obj->Routine = routine;

		//tst.b	(v_bossstatus).w
		//beq.s	loc_9180
                if (v_bossstatus != 0)
                {
		    //btst	#4,(v_vbla_byte).w  -------------------
		    //beq.s	loc_9180            ADDITIONAL CONDITIONS
		    
                    //neg.w	obVelX(a0)
                    obj->VelocityX = -obj->VelocityX;

		    //bchg	#0,obRender(a0)
                    obj->Render = obj->Render ^ 1;
                }
            }
        }
        
        //loc_9180:
	//bra.w	DisplaySprite
        DisplaySprite(obj);
    }

}   //; ===========================================================================

//loc_9184:				; XREF: Anml_Index
void loc_9184()                         //animals 0,2,3,4,6 after reaching ground
{
    //bsr.w	ObjectFall
    ObjectFall(obj);
		
    //move.b	#1,obFrame(a0)
    obj->Frame = 1;

    //tst.w	obVelY(a0)
    //bmi.s	loc_91AE
    if (obj->VelocityY >= 0)
    {
        //move.b	#0,obFrame(a0)
        obj->Frame = 0;
 
	//jsr	ObjFloorDist
        signed short floorDist = ObjFloorDist(obj);

	//tst.w	d1
	//bpl.s	loc_91AE
        if (floorDist < 0)
        {
	    //add.w	d1,obY(a0)
            obj->Y = obj->Y + floorDist;

	    //move.w	$34(a0),obVelY(a0)
            obj->VelocityY = ptrgetobjvariableword(0x34, obj);
        } 
    }
    
    //loc_91AE:
    //tst.b	obSubtype(a0)
    //bne.s	loc_9224
    if (obj->Subtype != 0) { loc_9224(); }      //if not from a destroyed enemy
    else
    {
	//tst.b	obRender(a0)
        //bpl.w	DeleteObject
        if (obj->Render < 0x80) { DeleteObject(obj); }
	else
        {
	    //bra.w	DisplaySprite
            DisplaySprite(obj);
        }
    }
}   //; ===========================================================================

void loc_91C0()                         //animals 1&5 after reaching floor
{
    //loc_91C0:				; XREF: Anml_Index
    //bsr.w	SpeedToPos
    SpeedToPos(obj);

    //addi.w	#$18,obVelY(a0)
    obj->VelocityY = obj->VelocityY + 0x18;

    //tst.w	obVelY(a0)
    //bmi.s	loc_91FC
    if (obj->VelocityY >= 0)
    {	
        //jsr	ObjFloorDist
        signed short floorDist = ObjFloorDist(obj);

	//tst.w	d1
        //bpl.s	loc_91FC
        if (floorDist < 0)
        {
	    //add.w	d1,obY(a0)
            obj->Y = obj->Y + floorDist;

	    //move.w	$34(a0),obVelY(a0)
            obj->VelocityY = ptrgetobjvariableword(0x34, obj);
		
            //tst.b	obSubtype(a0) 
            //beq.s	loc_91FC
	    //cmpi.b	#$A,obSubtype(a0)
	    //beq.s	loc_91FC
            if ((obj->Subtype != 0) && (obj->Subtype != 10))
            {
                //neg.w	obVelX(a0)
                obj->VelocityX = -obj->VelocityX;

		//bchg	#0,obRender(a0)
                obj->Render = obj->Render ^ 1;
            }
        }
    }
    
    //loc_91FC:
    //subq.b	#1,obTimeFrame(a0)
    obj->TimeFrame = obj->TimeFrame - 1;

    //bpl.s	loc_9212
    if (obj->TimeFrame < 0)
    {
	//move.b	#1,obTimeFrame(a0)
        obj->TimeFrame = 1;

	//addq.b	#1,obFrame(a0)
        obj->Frame = obj->Frame + 1;

	//andi.b	#1,obFrame(a0)
        obj->Frame = obj->Frame & 1;
    }

    //loc_9212:
    //tst.b	obSubtype(a0)
    //bne.s	loc_9224
    if (obj->Subtype != 0) { loc_9224(); }
    else
    {
	//tst.b	obRender(a0)
        //bpl.w	DeleteObject
        if (obj->Render < 0x80) { DeleteObject(obj); }
	else
        {
            //bra.w	DisplaySprite
            DisplaySprite(obj);
        }
    }
}   //; ===========================================================================

//loc_9224:				; XREF: Anml_Index
void loc_9224()
{
    //move.w	obX(a0),d0
    word anmlX = obj->X;

    //sub.w	(v_player+obX).w,d0
    signed short distPlayer = anmlX - player.X;

    //bcs.s	loc_923C
    if (distPlayer < 0)
    {
        //subi.w	#$180,d0
        distPlayer = distPlayer - 0x180;

        //bpl.s	loc_923C
        if (distPlayer < 0)
        {
	    //tst.b	obRender(a0)
            if (obj->Render < 0x80)
            {
		//bpl.w	DeleteObject
                DeleteObject(obj);
                
                return;
            }
        }
    }

    //loc_923C:
    //bra.w	DisplaySprite
    DisplaySprite(obj);
}

//; ===========================================================================

//loc_9240:				; XREF: Anml_Index
void loc_9240()
{
    //tst.b	obRender(a0)
    if (obj->Render < 0x80)
    {
        //bpl.w	DeleteObject
        DeleteObject(obj);
    }

    //subq.w	#1,$36(a0)
    //bne.w	loc_925C
    ptrsubobjvariableword(0x36,obj,1)
    if (ptrgetobjvariableword(0x36,obj) == 0);
    {
        //move.b	#2,obRoutine(a0)
        obj->Routine = 2;

	//move.b	#3,obPriority(a0)
        obj->Priority = 3;
    }

    //loc_925C:
    //bra.w	DisplaySprite
    DisplaySprite(obj);

}   //; ===========================================================================

//loc_9260:				; XREF: Anml_Index
void loc_9260()
{
    //bsr.w	sub_9404
    //bcc.s	loc_927C
    if (sub_9404() < 0)
    { 
        //move.w	$32(a0),obVelX(a0)
        obj->VelocityX = ptrgetobjvariableword(0x32, obj);

	//move.w	$34(a0),obVelY(a0)
        obj->VelocityY = ptrgetobjvariableword(0x34, obj);

	//move.b	#$E,obRoutine(a0)
        obj->Routine = 14;

	//bra.w	loc_91C0
        loc_91C0();
    }
    else
    {
        //; ===========================================================================
        //loc_927C:
	//bra.w	loc_9224
        loc_9224();
    }
}   //; ===========================================================================

//loc_9280:				; XREF: Anml_Index
void loc_9280()
{
    //bsr.w	sub_9404
    //bpl.s	loc_92B6
    if (sub_9404() < 0)
    {
        //clr.w	obVelX(a0)
        obj->VelocityX = 0;

	//clr.w	$32(a0)
        ptrsetobjvariableword(0x32, obj, 0);

	//bsr.w	SpeedToPos
        SpeedToPos(obj);

	//addi.w	#$18,obVelY(a0)
        obj->VelocityY = obj->VelocityY + 0x18;

	//bsr.w	loc_93C4
        loc_93C4();

	//bsr.w	loc_93EC
        loc_93EC();

	//subq.b	#1,obTimeFrame(a0)
        obj->TimeFrame = obj->TimeFrame - 1;

	//bpl.s	loc_92B6
        if (obj->TimeFrame < 0)
        { 
            //move.b	#1,obTimeFrame(a0)
            obj->TimeFrame = 1;

	    //addq.b	#1,obFrame(a0)
            obj->Frame = obj->Frame + 1;

	    //andi.b	#1,obFrame(a0)
            obj->Frame = obj->Frame & 1;
        }
    }
    else
    {
        //loc_92B6:
	//bra.w	loc_9224
        loc_9224();
    }
}   //; ===========================================================================

//loc_92BA:				; XREF: Anml_Index
void loc_92BA()
{
    //bsr.w	sub_9404
    //bpl.s	loc_9310
    if (sub_9404() < 0)
    { 
        //move.w	$32(a0),obVelX(a0)
        obj->VelocityX = ptrgetobjvariableword(0x32, obj);

	//move.w	$34(a0),obVelY(a0)
        obj->VelocityY = ptrgetobjvariableword(0x34, obj);

	//move.b	#4,obRoutine(a0)
        obj->Routine = 4;

	//bra.w	loc_9184
        loc_9184();
    }
    else
    {
        //; ===========================================================================
        //loc_9310:
        //bra loc_9224
        loc_9224();
    }
}

//loc_92D6:				; XREF: Anml_Index
void loc_92D6()
{
    //bsr.w	ObjectFall
    ObjectFall(obj);
		
    //move.b	#1,obFrame(a0)
    obj->Frame = 1;

    //tst.w	obVelY(a0)
    //bmi.s	loc_9310
    if (obj->VelocityY >= 0)
    {
        //move.b	#0,obFrame(a0)
        obj->Frame = 0;
 
	//jsr	ObjFloorDist
        signed short floorDist = ObjFloorDist(obj);

	//tst.w	d1
	//bpl.s	loc_9310
        if (floorDist < 0)
        {
	    //not.b	$29(a0)
            obj->Variables[0] = ~obj->Variables[0];
		
            //bne.s	loc_9306
            if (obj->Variables[0] == 0)
            {
                //neg.w	obVelX(a0)
                obj->VelocityX = -obj->VelocityX;

		//bchg	#0,obRender(a0)
                obj->Render = obj->Render ^ 1;
            }
            
            //add.w	d1,obY(a0)
            obj->Y = obj->Y + floorDist;
  
	    //move.w	$34(a0),obVelY(a0)
            obj->VelocityY = ptrgetobjvariableword(0x34, obj);
        }
    }
    
    //loc_9310:
    //bra.w	loc_9224
    loc_9224();
}        


//loc_9314:				; XREF: Anml_Index
void loc_9314()
{
    //bsr.w	sub_9404
    //bpl.s	loc_932E
    if (sub_9404() < 0)
    {
        //clr.w	obVelX(a0)
        obj->VelocityX = 0;

	//clr.w	$32(a0)
        ptrsetobjvariableword(0x32, obj, 0);

	//bsr.w	ObjectFall
        ObjectFall(obj);

	//bsr.w	loc_93C4
        loc_93C4();

	//bsr.w	loc_93EC
        loc_93EC();
    }
    else
    {
        //loc_932E:
	//bra.w	loc_9224
        loc_9224();
    }

}   //; ===========================================================================

//loc_9332:				; XREF: Anml_Index
void loc_9332()
{
    //bsr.w	sub_9404
    //bpl.s	loc_936C
    if (sub_9404() < 0)
    {
        //bsr.w	ObjectFall
        ObjectFall(obj);

	//move.b	#1,obFrame(a0)
        obj->Frame = 1;

	//tst.w	obVelY(a0) 
        //bmi.s	loc_936C
        if (obj->VelocityY >= 0)
	{	
	    //move.b	#0,obFrame(a0)
            obj->Frame = 0;

	    //jsr	ObjFloorDist
            signed short floorDist = ObjFloorDist(obj);

	    //tst.w	d1
	    //bpl.s	loc_936C
            if (floorDist < 0)
            {
		//neg.w	obVelX(a0)
                obj->VelocityX = -obj->VelocityX;

		//bchg	#0,obRender(a0)
                obj->Render = obj->Render ^ 1;

		//add.w	d1,obY(a0)
                obj->Y = obj->Y + floorDist;
  
		//move.w	$34(a0),obVelY(a0)
                obj->VelocityY = ptrgetobjvariableword(0x34, obj);

            }
        }
    }
    //loc_936C:
    //bra.w	loc_9224
    loc_9224();

}   //; ===========================================================================

//loc_9370:				; XREF: Anml_Index
void loc_9370()
{
    //bsr.w	sub_9404
    //bpl.s	loc_93C0
    if (sub_9404() < 0)
    {
        //bsr.w	SpeedToPos
        SpeedToPos(obj);

	//addi.w	#$18,obVelY(a0)
        obj->VelocityY = obj->VelocityY + 0x18;

	//tst.w	obVelY(a0)
        //bmi.s	loc_93AA
        if (obj->VelocityY >= 0)
        {
	    //jsr	ObjFloorDist
            signed short floorDist = ObjFloorDist(obj);

	    //tst.w	d1
            //bpl.s	loc_93AA
            if (floorDist < 0)
	    {	
		//not.b	$29(a0)
                obj->Variables[0] = ~obj->Variables[0];
		
                //bne.s	loc_93A0
                if (obj->Variables[0] == 0)
                {
		    //neg.w	obVelX(a0)
                    obj->VelocityX = -obj->VelocityX;

		    //bchg	#0,obRender(a0)
                    obj->Render = obj->Render ^ 1;
                }

                //loc_93A0:
	        //add.w	d1,obY(a0)
                obj->Y = obj->Y + floorDist;
  
	        //move.w	$34(a0),obVelY(a0)
                obj->VelocityY = ptrgetobjvariableword(0x34, obj);
            }
        }

        //loc_93AA:
        //subq.b	#1,obTimeFrame(a0)
        obj->TimeFrame = obj->TimeFrame - 1;

	//bpl.s	loc_93C0
        if (obj->TimeFrame < 0)
        { 
            //move.b	#1,obTimeFrame(a0)
            obj->TimeFrame = 1;

	    //addq.b	#1,obFrame(a0)
            obj->Frame = obj->Frame + 1;

	    //andi.b	#1,obFrame(a0)
            obj->Frame = obj->Frame & 1;
        }
    }
     
    //loc_93C0:
    //bra.w	loc_9224
    loc_9224();

}   //; ===========================================================================

//loc_93C4:
void loc_93C4()
{
    //move.b	#1,obFrame(a0)
    obj->Frame = 1;
	
    //tst.w	obVelY(a0) 
    //bmi.s	locret_93EA
    if (obj->VelocityY >= 0)
    {	
	//move.b	#0,obFrame(a0)
        obj->Frame = 0;

	//jsr	ObjFloorDist
        signed short floorDist = ObjFloorDist(obj);

	//tst.w	d1
	//bpl.s	locret_93EA
        if (floorDist < 0)
        {
	    //add.w	d1,obY(a0)
            obj->Y = obj->Y + floorDist;
  
	    //move.w	$34(a0),obVelY(a0)
            obj->VelocityY = ptrgetobjvariableword(0x34, obj);

        }
    }
}

//; ===========================================================================

//loc_93EC:
void loc_93EC()
{
    //bset	#0,obRender(a0)
    obj->Render = obj->Render | 1;

    //move.w	obX(a0),d0
    word anmlX = obj->X;

    //sub.w	(v_player+obX).w,d0
    signed short distPlayer = player.X - anmlX;

    //bcc.s	locret_9402
    if (distPlayer < 0)
    {
        //bclr	#0,obRender(a0)
        obj->Render = obj->Render - (obj->Render & 1);
    }

    //locret_9402:
    //rts	
}

//; ||||||||||||||| S U B	R O U T	I N E |||||||||||||||||||||||||||||||||||||||


//sub_9404:
signed short sub_9404()
{
    //move.w	(v_player+obX).w,d0 
    word playerX = player.X;

    //sub.w	obX(a0),d0
    //subi.w	#$B8,d0
    signed short distAnml = (playerX - obj->X) - 0xB8;
  
    //rts	
}   //; End of function sub_9404
